<template>
  <section>
    <div class="filter-container">
      <common-input @keyup.enter.native="handleFilter" class="w200" placeholder="名称/编号" v-model="listQuery.keyword" />
      <!-- <el-date-picker
          class="ml10"
          size="mini"
          v-model="listQuery.contractEnd"
          type="date"
        format="yyyy年MM月dd日"
        value-format="yyyy-MM-dd"
          placeholder="到期时间">
        </el-date-picker> -->
      <el-button size="mini" class="ml10" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button size="mini" class="ml10" @click="handleCreate" type="primary" icon="el-icon-plus">新增</el-button>
    </div>
    <!-- <el-tabs size="mini" :before-leave='leaveTab' v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="全部" name="0"></el-tab-pane>
      <el-tab-pane label="已审核" name="1"></el-tab-pane>
      <el-tab-pane label="待审核" name="2"></el-tab-pane>
      <el-tab-pane label="被驳回" name="3"></el-tab-pane>
    </el-tabs> -->
    <el-table :data="list" style="width: 100%">

      <!-- <el-table-column align="center" label="供应商编号">
                <template slot-scope="scope">
                    <span>{{scope.row.code}}</span>
                </template>
</el-table-column> -->
      <el-table-column align="left" label="合伙人姓名">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <el-table-column align="right" label="余额">
        <template slot-scope="scope">
          <span>￥{{ scope.row.money }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="联系人">
        <template slot-scope="scope">
          <span>{{ scope.row.consignee }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="联系电话">
        <template slot-scope="scope">
          <span>{{ scope.row.contactPhone }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" label="签约时间">
        <template slot-scope="scope">
          <span>{{ scope.row.contractStart }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="到期时间">
        <template slot-scope="scope">
          <span>{{ scope.row.contractEnd }}</span>
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="关闭提现">
        <template slot-scope="scope">
          <span v-if="scope.row.closeWithdraw == 1">是</span>
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" label="状态">
        <template slot-scope="scope">
          <el-tag :type="getStatusColor(scope.row)">{{ scope.row.statusText }}</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="子账号">
        <template slot-scope="scope">
          <el-button type="text" @click="handleAccount(scope.row)">管理</el-button>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-dropdown>
            <el-button type="text">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleUpdate(scope.row)">编辑</el-dropdown-item>
              <!-- <el-dropdown-item v-if="scope.row.status==0" @click.native="handleCheck(scope.row)">审核</el-dropdown-item> -->
              <!-- <el-dropdown-item v-if="scope.row.status==1" @click.native="handleCheck2(scope.row)">取消审核</el-dropdown-item> -->
              <!-- <el-dropdown-item v-if="scope.row.status==0&&scope.row.isFront==1" @click.native="handleRefuse(scope.row)">拒绝审核</el-dropdown-item> -->
              <el-dropdown-item @click.native="handleDelete(scope.row)">删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <span v-else>-</span> -->
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page.sync="listQuery.pageNum" :page-sizes="[20, 30, 50]" :page-size="listQuery.pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
    </div>
  </section>
</template>

<script>
import {
  agency_list,
  agency_del,
  agency_check,
  agency_check2,
  agency_refuse
} from '../../api/partner';
export default {
  data() {
    return {
      list: null,
      listLoading: true,
      listQuery: {
        pageNum: 1,
        pageSize: 20,
        keyword: undefined

      },
      total: null,
      activeName: '0'
    };
  },
  mounted() {
  },
  created() {
    this.getList();
  },

  methods: {
    getList() {
      this.listLoading = true;
      agency_list(this.listQuery).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.listLoading = false;
      })
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.num = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
    handleClick(tab, event) {
      this.listQuery.status = this.activeName;
      this.handleFilter();
      // console.log(this.activeName)
    },
    leaveTab(activeName, oldActiveName) {
      // console.log(activeName)
      // return false;
    },
    handleCreate() {
      this.$router.push("/partner/partner_create")
    },
    handleUpdate(row) {
      this.$router.push("/partner/partner_edit?id=" + row.id)
    },
    getStatusColor(row) {
      if (row.status === 1) {
        return "success"
      }

      return "danger"
    },
    handleDelete(row) {
      console.log(row)
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          agency_del(row.id)
            .then(() => {
              this.$message.success("供应商删除成功");
              const index = this.list.indexOf(row);
              this.list.splice(index, 1);
            });
        }).catch(() => { });
    },
    handleCheck(row) {
      this.$confirm('确定审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          agency_check(row.id)
            .then(() => {
              this.$message.success("供应商审核成功");
              this.getList();
            });
        }).catch(() => { });
    },
    handleCheck2(row) {
      this.$confirm('确定取消审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          agency_check2(row.id)
            .then(() => {
              this.$message.success("供应商取消审核成功");
              this.getList();
            });
        }).catch(() => { });
    },
    handleRefuse(row) {
      this.$confirm('确定拒绝审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          agency_refuse(row.id)
            .then(() => {
              this.$message.success("供应商拒绝审核成功");
              this.getList();
            });
        }).catch(() => { });
    },
    handleAccount(row) {
      this.$router.push("/partner/partner_account?id=" + row.id)
    }
  }
};
</script>
